import React, { Component } from 'react';
import {Link} from 'react-router';
import InformationComponent from '../../Component/OrderManage/InformationComponent';
import Top from '../CommonComponent/Top'
import Empty from '../../Component/CommonComponent/Empty';
import CommonBtn from '../../Component/CommonComponent/CommonBtn';
import {AddressList} from '../../Action/auth'

export default class ChooseAddress extends Component {

    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            addressList : []
        };
      }

    async componentWillMount() {
        await this.getAddressList()
    }

    async getAddressList(){
       await AddressList()
        .then(res=>{
            this.setState({addressList:res.resultList})
        })
        .catch(err=>{
            console.warn('获取地址列表错误',err)
        })
    }

    render() {
        const {addressList} = this.state
        console.log('addressList=======>',addressList == '')
        return (
            <div>
                <Top
                    title = {'选择收货地址'}
                />
                <div className="containerNav" style={{top:50,bottom:75}}>
                    {
                        addressList == ''||addressList == null?
                            <Empty />
                            :
                        addressList&&addressList.map((el,index)=>{
                            return (
                                <InformationComponent
                                    name={el.name}
                                    phone={el.mobile}
                                    path={el.address?el.address:''+el.detail?el.detail:''}
                                />
                            )
                        })
                    }
                </div>
                <div className="flex pf width100" style={{bottom:40}}>
                    <Link to="/deliveredInformation" className="flex-1">
                        <CommonBtn
                            title={'添加地址'}
                        />
                    </Link>

                </div>
            </div>
        );
    }
}
